# -*- coding: utf-8 -*-

'''eof
name:学位
code:IG05_EduDegree
tableName:
columnName:
groups:个人通用模块
dependencies:IC_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''


import sys
import pandas as pd
import json
from datetime import datetime


def FormatData(tableName):
    try:
        ic = IC_DSJ.get("data").get(tableName)
        return ic if isinstance(ic, list) else [{}]
    except:
        return [{}]

'''
IG05:学位，指标值为：博士、硕士、名誉博士、学士、其他；否则，指标为缺失值
IF 指标值 in[其他、学士] then 1;
IF 指标值 in[硕士、博士、名誉博士] then 2
IF 指标值 为 缺失值 then 缺失值
'''
def getIG05():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    edu_degree_list = [u'名誉博士', u'博士', u'硕士', u'学士', u'其他']
    try:
        ICRIdentity = FormatData("ICRIdentity")
        if ICRIdentity == [{}]:
            return u'缺失值'
        else:
            if len(ICRIdentity) >= 1:
                for i in ICRIdentity:
                    edu_degree = i.get("eduDegree")
                    if edu_degree not in null_type_list and edu_degree in edu_degree_list:
                        if edu_degree in [u'学士', u'其他']:
                            return 1
                        elif edu_degree in [u'名誉博士', u'博士', u'硕士']:
                            return 2
                    else:
                        return u'缺失值'
                return u'缺失值'
            else:
                return u'缺失值'
    except:
        return u'缺失值'


if __name__ == "__main__":
    file_obj = open(r'../data/IG/IG05_EduDegree/IC_DSJ.json', 'r')
    content = file_obj.read()
    IC_DSJ = json.loads(content, strict=False)
    aa = getIG05()
    print aa

result = getIG05()

